<template>
  <view class="ithui-content">
    <view class="ithui-view">
      <view class="view-info">
        <view class="box">
          <view class="tx">
            <view class="tx-grid">
              <view class="tx-grid-text">
                <view class="title" style="margin-bottom: 10rpx">可用余额</view>
                <view class="money">
                  <text>{{ balance }}</text>
                  <text class="money-b">元</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="top">
          <u-subsection :list="tabs" fontSize="32" activeColor="#ff8440" :current="tabIndex"
                        @change="changeTab"></u-subsection>
        </view>
        <view class="list-view">
          <u-empty v-if="list.length === 0" style="margin-top: 40rpx;" mode="order" text="没有记录" iconSize="140"
                   textSize="32">
          </u-empty>
          <view class="list-item" v-for="(item, index) in list" :key="index" hover-class="hover"
                :hover-stay-time="150" bindtap="detail">
            <view class="content-box">
              <view class="des-box">
                <view class="time">{{ item.create_time }}</view>
              </view>
            </view>
            <view class="money" :class="{ less: is_withdraw }">
              + {{ item.amount }}
            </view>
          </view>
<!--          <view class="list-item" v-for="(item, index) in list" :key="index" hover-class="hover"-->
<!--                :hover-stay-time="150" bindtap="detail">-->
<!--            <view class="content-box">-->
<!--              <view class="des-box">-->
<!--                <view class="tit">-->
<!--                  {{ item.name }}-->
<!--                </view>-->
<!--                <view v-if="tabIndex == 3" class="source"-->
<!--                      :style="{ color: item.status == 1 ? '#4caf50' : item.status == 2 ? '#00b7ff' : '#ff1e0f' }">-->
<!--                  提现{{ item.status == 1 ? '成功' : item.status == 2 ? '处理中' : '失败' }}-->
<!--                </view>-->
<!--                <view class="time">{{ item.create_time }}</view>-->
<!--              </view>-->
<!--            </view>-->
<!--            <view class="money" :class="{ less: is_withdraw }">-->
<!--              {{ is_withdraw ? '-' : '+' }}{{ tabIndex == 3 ? item.real_money : item.money }}-->
<!--            </view>-->
<!--          </view>-->
        </view>
        <view class="tip">仅显示近一年内的收支记录</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      is_withdraw: false,
      list: [],
      userData: {},
      showModal: false,
      date: 'incomeMonth',
      tabs: ['充值记录'],
      tabIndex: 0,
      userInfo: {
        amount: 100
      },
      balance: '0.00'
    }
  },
  onLoad() {
    this.initData();
  },
  methods: {
    async initData() {
      this.tabIndex = 0;
      if (!this.$store.state.userInfo.id) {
        uni.showToast({
          title: '请先登录',
          icon: 'none',
        });
        return;
      }
      this.$api.memberDetail(this.$store.state.userInfo.id).then((res) => {
        this.balance = res.balance || '0.00';
      });
      this.$api.rechargeList({
        member_id: this.$store.state.userInfo.id
      }).then(res => {
        this.list = res;
      })
    },
    async getFundList() {
      this.list = await this.$api.mock(this.date);
    },
    changeTab(index) {
      this.tabIndex = index;
      this.list = []
      if (this.tabIndex == 0) {
        this.date = 'incomeMonth';
        this.is_withdraw = false;
      } else if (this.tabIndex == 1) {
        this.date = 'incomeToday';
        this.is_withdraw = false;
      } else if (this.tabIndex == 2) {
        this.date = 'incomeYesterday';
        this.is_withdraw = false;
      } else if (this.tabIndex == 3) {
        this.date = 'incomeList';
        this.is_withdraw = true;
      }
      uni.showLoading({
        title: '加载中'
      });
      this.getFundList();
      setTimeout(() => {
        uni.hideLoading();
      }, 500);
    },
    navTo(url) {
      uni.navigateTo({
        url
      });
    }
  },
  onPullDownRefresh() {
    uni.showLoading({
      title: '加载中'
    });
    this.showModal = false
    this.initData();
    setTimeout(() => {
      uni.hideLoading();
    }, 500);
    setTimeout(function() {
      uni.stopPullDownRefresh();
    }, 500);
  }
}
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
  align-items: center;
  padding: 50rpx;
  position: relative;

  &-one {
    flex: 1;
    min-width: 0;
    font-size: 26rpx;
    color: #333;

    &-text {
      margin: 10rpx 0;
      color: #f5f5f5;
      font-weight: normal;
    }
  }
}


.ithui {
  &-content {
    padding: 20rpx;
    .h5title {
      width: 100%;
      height: 120rpx;
      text-align: center;
      line-height: 200rpx;
      color: white;
      font-size: 34rpx;
      font-weight: bold;
      background: linear-gradient(to right, #ff8440, #ff1e0f);
    }

    .list-view {
      position: relative;
      width: 100%;
      height: 100%;
      overflow: hidden;
    }

    .list-item {
      width: 100%;
      padding: 30rpx 28rpx;
      box-sizing: border-box;
      background: #fff;
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      border-bottom: 1rpx solid #eaeef1;
    }

    .item-last::after {
      left: 0 !important;
    }

    .content-box {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
    }

    .des-box {
      min-height: 80rpx;
      padding-left: 28rpx;
      box-sizing: border-box;
      vertical-align: top;
      color: #333;
      font-size: 28rpx;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .tit {
      font-size: 32rpx;
      max-width: 420rpx;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .source {
      margin: 12rpx 0;
    }

    .time {
      color: #888;
    }

    .money {
      font-size: 38rpx;
      font-weight: 500;
      color: #ff1e0f;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding-left: 20rpx;
    }

    .less {
      color: #4caf50 !important;
    }

    .tip {
      margin-top: 50rpx;
      display: flex;
      justify-content: center;
      align-content: center;
      font-size: 24rpx;
      color: #888;
    }

  }

  &-view {
    width: 100%;
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;

    .view-info {
      width: 100%;
      height: 100%;
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      position: relative;
      padding-bottom: 116rpx;
      .top {
        margin-bottom: 20rpx;
      }
      .box {
        width: 100%;
        background: white;
        border-radius: 10rpx;
        margin: 0 auto 20rpx;
        box-shadow: 0 6rpx 20rpx #e7e7e7;

        .tx {
          padding-top: 26rpx;
          padding-bottom: 26rpx;
          overflow: hidden;
          display: flex;
          justify-content: space-between;
          align-content: center;

          &-grid {
            box-sizing: border-box;

            &:first-child {
              margin-left: 40rpx;
            }

            &-comm-sign {
              display: block;
              border-radius: 40rpx 0 0 40rpx;
              font-size: 26rpx;
              padding: 16rpx 44rpx;
              background: linear-gradient(to right, #fef082, #ffc551);
              background-color: #fef082;
              color: #cf4400;
            }

            &-text {
              display: block;
              color: #333;
              font-size: 26rpx;
              white-space: nowrap;
              text-overflow: ellipsis;
              overflow: hidden;

              .title {
                font-size: 32rpx;
                font-weight: normal;
                color: #ff6423;
              }

              .money {
                font-size: 60rpx;
                color: #ff6423;
                letter-spacing: 2rpx;
                margin-bottom: 10rpx;

                &-b {
                  font-size: 28rpx;
                }
              }
            }
          }
        }

        .palace {
          padding-bottom: 20rpx;
          overflow: hidden;
          display: flex;
          justify-content: center;

          &-grid {
            flex: 1;
            position: relative;
            box-sizing: border-box;

            &:not(:last-child) {
              &:after {
                width: 1rpx;
                height: 80rpx;
                background: #fddece;
                content: ' ';
                display: inline-block;
                position: absolute;
                top: 0;
                right: 0;
              }
            }

            &-text {
              display: block;
              text-align: center;
              color: #333;
              font-size: 32rpx;
              white-space: nowrap;
              text-overflow: ellipsis;
              overflow: hidden;

              &-name {
                font-size: 26rpx;
                font-weight: normal;
                color: #ff8a4a;
              }

              &-data {
                font-size: 32rpx;
                color: #ff8a4a;
                letter-spacing: 2rpx;
                margin-bottom: 5rpx;

                &-b {
                  font-size: 20rpx;
                }
              }
            }
          }
        }
      }
    }
  }

}
</style>
